package com.example.baseapp.dto;

import com.example.baseapp.entity.OrderInfo;
import com.example.baseapp.common.OrderStatusEnum;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
public class OrderListDTO {
    private Long id;
    private String orderNo;
    private Long userId;
    private String userName;
    private String orderDate;
    private String menuDate;
    private String mealType;
    private String dishList;
    private BigDecimal totalAmount;
    private String status;
    private String statusText;
    private String paymentMethod;
    private String paymentTime;
    private String remark;
    private String createTime;
    private String updateTime;
    private String userNickname;
    private String userAvatar;
    private String userPhone;
    private String userDepartment;
    private String userAddress;
    
    public OrderListDTO(OrderInfo orderInfo) {
        this.id = orderInfo.getId();
        this.orderNo = orderInfo.getOrderNo();
        this.userId = orderInfo.getUserId();
        this.userName = orderInfo.getUserName();
        this.orderDate = orderInfo.getOrderDate() != null ? orderInfo.getOrderDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null;
        this.menuDate = orderInfo.getMenuDate() != null ? orderInfo.getMenuDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : null;
        this.mealType = orderInfo.getMealType();
        this.dishList = orderInfo.getDishList();
        this.totalAmount = orderInfo.getTotalAmount();
        this.status = orderInfo.getStatus();
        this.statusText = OrderStatusEnum.getStatusText(orderInfo.getStatus());
        this.paymentMethod = orderInfo.getPaymentMethod();
        this.paymentTime = orderInfo.getPaymentTime() != null ? orderInfo.getPaymentTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null;
        this.remark = orderInfo.getRemark();
        this.createTime = orderInfo.getCreateTime() != null ? orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null;
        this.updateTime = orderInfo.getUpdateTime() != null ? orderInfo.getUpdateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null;
        this.userNickname = orderInfo.getUserNickname();
        this.userAvatar = orderInfo.getUserAvatar();
        this.userPhone = orderInfo.getUserPhone();
        this.userDepartment = orderInfo.getUserDepartment();
        this.userAddress = orderInfo.getUserAddress();
    }
} 